<?php
/*
 * 
 * This funcionality help to create dinamic html 
 * for dinamic information.
 * 
 * 
 * @autor alvaro jose peralta alvaro.peralta@aiesec.net
 */
class PresentationUtils {
	
	
	/**
	 * 
	 * 
	 * 
	 * @param $name name of cbo for the form
	 * @param $lstOptions obj ArrayList of base/list/ArrayList
	 * @param $class can be null if the cbo not use csc
	 * @return unknown_type
	 */
	public static function getCboOption($name,$lstOptions,$class){
		return PresentationUtils::getCboOptionAddInfo($name,$lstOptions,$class,'');
	}
	
	
	/**
	 * 
	 * 
	 * 
	 * @param $name name of cbo for the form
	 * @param $lstOptions obj ArrayList of base/list/ArrayList
	 * @param $class can be null if the cbo not use csc
	 * @param $adicionalInfo could be use to add info in the header of cbo
	 * @return unknown_type
	 */
	public static function getCboOptionAddInfo($name,$lstOptions,$class,$adicionalInfo){
		
		$stHTML = '<select ';
		
		if (!is_null($class)){
			$stHTML = $stHTML.'class="' . $class . '"';
		}
		
		$stHTML = $stHTML.' name="' . $name . '" id="'.$name.'"';
		
		if (!is_null($adicionalInfo)){
			$stHTML = $stHTML.$adicionalInfo.'>';
		}else{
			$stHTML = $stHTML.'>';
		}
		
		// add null option for cbo
		$stHTML =$stHTML.' <option selected="selected" value="">-- please select --</option> ';
		
		$lovTO = new LovTO();
		// foreach LovTO into $lstOptions add option value in cbo
		while($lstOptions->hasNext()){
			$lovTO = $lstOptions->next();
			$stHTML =$stHTML.'<option value="'.$lovTO->value.'">'.$lovTO->text.'</option>';
		}							
		$stHTML =$stHTML.'</select>';					
		
		return $stHTML;
	}	
	
	/**
	 * 
	 * @param $lstOptions list of LovTO to fill the table with checkbox ArrayList
	 * @param $class the class for each td String
	 * @param $colum number of colum to show in html int
	 * @return unknown_type
	 * @author sebastian
	 */
	public static function getCheckBox($lstOptions,$class,$colum){
		
		$stHTML = '<table border="0" cellspacing="0" cellpadding="0"> <tbody>';
		$control=$colum;
		$lovTO = new LovTO();
		// foreach LovTO into $lstOptions add option value in cbo
		while($lstOptions->hasNext()){
			if($colum%$control==0){
				$stHTML =$stHTML.'<tr>';
			}
			$lovTO = $lstOptions->next();
			//////////////////////////////////////////////////$lovTO->value///////////lovTO->name///////lovTO->text
			$stHTML =$stHTML.'<td class= "'.$class.'">   <input type="checkbox" value="'.$lovTO->value.'" name="'.$lovTO->name.'" id="'.$lovTO->name.'"/> </td> <td class= "'.$class.'">'.$lovTO->text.'</td>';
			$control=$control+1;
			if($control==$colum*2){
				$stHTML =$stHTML.'</tr>';
				$control=$colum;
			}
			
		}				
		$stHTML =$stHTML.'</tr> </tbody> </table>';
		return $stHTML;
	}	
	
}